package demo;

public class P278 {

    public static void main(String[] args) {
        P278 p278= new P278();
        p278.firstBadVersion(5);
    }

    public  boolean isBadVersion(int n){
        return n >= 4;
    }


    public int firstBadVersion(int n) {


        int min=1;
        int max=n;

        while(min<max){


            int mid= min+(max-min)/2;

            if( ! isBadVersion(mid)   )
                min= mid+1;
            else if (  isBadVersion(mid) && isBadVersion(mid-1) && mid-1 >=1 )
                max= mid-1;
            else
                return mid;
        }

        return min;
    }
}
